package com.qdlc.p2p.dal.model;

import com.qdlc.p2p.common.exception.AccountException;
import com.qdlc.p2p.common.exception.BusinessException;
import com.qdlc.p2p.common.util.Page;
import com.qdlc.p2p.dal.dto.MovieConfig;
import org.springframework.beans.BeanUtils;

/**
 * 电影票配置Model
 * 
 * @author ygw
 * @version 1.0
 * @since 2016年1月22日
 */
public class MovieConfigModel extends MovieConfig {

	private static final long serialVersionUID = 1L;

	/** 当前页码 */
	private int page;
	
	/** 条件查询 */
	private String searchName;

	
	/** 每页数据条数 */
	private int size = Page.ROWS;

	public static MovieConfigModel instance(MovieConfig movieConfig) {
		MovieConfigModel movieConfigModel = new MovieConfigModel();
		BeanUtils.copyProperties(movieConfig, movieConfigModel);
		return movieConfigModel;
	}

	public MovieConfig prototype() {
		MovieConfig movieConfig = new MovieConfig();
		BeanUtils.copyProperties(this, movieConfig);
		return movieConfig;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getSize() {
		return size > 0 ? size : Page.ROWS;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public String getSearchName() {
		return searchName;
	}

	public void setSearchName(String searchName) {
		this.searchName = searchName;
	}
	/**
	 * 金额最多只能保留两位小数
	 * 
	 * @param money
	 * @throws Exception
	 */
	public void checkMoney (double money) {
		String[] tem = String.valueOf(money).split("\\.");
		if (tem[1].length() > 2) {
			throw new AccountException("票价最多只能保留两位小数！", BusinessException.TYPE_JSON);
		}		
	}
}
